/*
 * ﻿Copyright (C) 2009-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.gwetons.logging.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap;
import com.newmainsoftech.gwetons.client.logging.JsniLoggerWrapFactory;
import com.newmainsoftech.gwetons.client.logging.JsniLoggerWrapFactoryImpl;
import com.newmainsoftech.gwetons.logging.shared.LoggerInitializerForTest;
import com.newmainsoftech.gwetons.shared.logging.LoggerWrap;
import com.newmainsoftech.gwetons.shared.logging.LoggerWrapFactory;

public abstract class JsniLoggerWrapAdaptedGwtTestCase extends GWTTestCase {
	// For logging --------------------------------------------------------------------------------
	abstract protected String getNameForLogging();
	
	private static LoggerInitializerForTest loggerInitializerForTest;
		public static LoggerInitializerForTest getLoggerInitializerForTest() {
			if ( loggerInitializerForTest == null) {
				LoggerInitializerForTestGinjector loggerInitializerForTestGinjector 
				= GWT.create( LoggerInitializerForTestGinjector.class);
				setLoggerInitializerForTest(
						loggerInitializerForTestGinjector.getLoggerInitializerForTest()
						);
			}
			return loggerInitializerForTest;
		}
		public static void setLoggerInitializerForTest( 
				LoggerInitializerForTest loggerInitializerForTest) {
			
			JsniLoggerWrapAdaptedGwtTestCase.loggerInitializerForTest = loggerInitializerForTest;
		}

	private JsniLoggerWrapFactory jsniLoggerWrapFactory;
		public JsniLoggerWrapFactory getJsniLoggerWrapFactory() {
			return jsniLoggerWrapFactory;
		}
		public void setJsniLoggerWrapFactory( 
				JsniLoggerWrapFactory jsniLoggerWrapFactory) {
			
			this.jsniLoggerWrapFactory = jsniLoggerWrapFactory;
			setLoggerWrap( null);
		}

		public LoggerWrapFactory getLoggerWrapFactory() {
			return getJsniLoggerWrapFactory();
		}
		
	private LoggerWrap loggerWrap;
		private LoggerWrap getLoggerWrap() {
			return loggerWrap;
		}
		public void setLoggerWrap( LoggerWrap loggerWrap) {
			this.loggerWrap = loggerWrap;
			setJsniLoggerWrap( null);
		}
		
	private JsniLoggerWrap jsniLoggerWrap;
		public JsniLoggerWrap getJsniLoggerWrap() {
			if ( jsniLoggerWrap == null) {
				setJsniLoggerWrap( 
						JsniLoggerWrapFactoryImpl.getJsniLoggerWrap( 
								null, 
								getLoggerWrap(), 
								getNameForLogging(), 
								getJsniLoggerWrapFactory()
								)
						);
			}
			return jsniLoggerWrap;
		}
		public void setJsniLoggerWrap( JsniLoggerWrap jsniLoggerWrap) {
			this.jsniLoggerWrap = jsniLoggerWrap;
		}
	// --------------------------------------------------------------------------------------------
}
